package com.rock.code.report.overview.service.impl;

import com.rock.code.base.service.impl.BaseServiceImpl;
import com.rock.code.common.handover.DataSource;
import com.rock.code.report.overview.dao.JbKpiOverviewDao;
import com.rock.code.report.overview.service.JbKpiOverviewService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 自动化运维概述 Service 实现
 *
 * @author xubh
 * @date 2018/01/21
 */
@Service
public class JbKpiOverviewServiceImpl extends BaseServiceImpl<JbKpiOverviewDao> implements JbKpiOverviewService {

    @Resource
    private JbKpiOverviewDao jbKpiOverviewDao;

    @Override
    @DataSource("inspect")
    public List queryPlatformHealthDegree() {
        return jbKpiOverviewDao.queryPlatformHealthDegree();
    }

    @Override
    @DataSource("inspect")
    public List queryBusinessHealthDegree() {
        return jbKpiOverviewDao.queryBusinessHealthDegree();
    }

    @Override
    @DataSource("inspect")
    public List queryTotalHealthDegree() {
        return jbKpiOverviewDao.queryTotalHealthDegree();
    }

    @Override
    @DataSource("itnmsdb")
    public List queryMonitorKpiCount() {
        return jbKpiOverviewDao.queryMonitorKpiCount();
    }

    @Override
    @DataSource("itnmsdb")
    public List queryMonitorKpi() {
        return jbKpiOverviewDao.queryMonitorKpi();
    }

    @Override
    @DataSource("itnmsdb")
    public List queryAlarmTendencyContrastList(String start_time, String end_time, String s) {
        HashMap map=new HashMap();
        map.put("start_time",start_time);
        map.put("end_time",end_time);
        map.put("event_class",s);
        return jbKpiOverviewDao.queryAlarmTendencyContrastList(map);
    }

    @Override
    @DataSource("cmdb")
    public List queryResourcceTargetOverviewService(){
        return jbKpiOverviewDao.queryResourcceTargetOverview();
    }

    @Override
    @DataSource("cmdb")
    public List queryResourceClassOverviewService(){
        return jbKpiOverviewDao.queryResourceClassOverview();
    }

    @Override
    @DataSource("cmdb")
    public  List queryResourceUseOverviewService(){
        return jbKpiOverviewDao.queryResourceUseOverview();
    }

    @Override
    @DataSource("inspect")
    public HashMap queryInspectOverviewService() {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String day=dateFormat.format(new Date());
        HashMap hashMap=new HashMap();
        long a=System.currentTimeMillis();
        List list1=jbKpiOverviewDao.queryTaskGroupSumOverview();
        long b=System.currentTimeMillis();
        System.out.println("查询总数==========="+(b-a)/1000+"秒");
        hashMap.put("allNum",list1);
        List listGroupTwo=new ArrayList();
        List listNum1=new ArrayList();
        List listNum2=new ArrayList();
        List list2 =new ArrayList();
        try{
            long c=System.currentTimeMillis();
            listGroupTwo = jbKpiOverviewDao.queryTaskGroupTwo();
            long d=System.currentTimeMillis();
            System.out.println("查询分组==========="+(d-c)/1000+"秒");

            long e=System.currentTimeMillis();
            for(int i = 0;i<listGroupTwo.size();i++){
                HashMap mapGroupTwo = (HashMap) listGroupTwo.get(i);
                mapGroupTwo.put("day",day);
                listNum1=jbKpiOverviewDao.queryInspectOverview(mapGroupTwo);
                HashMap map=(HashMap)listNum1.get(0);
                mapGroupTwo.putAll(map);
                listNum2=jbKpiOverviewDao.queryGroupTaskNum(mapGroupTwo);
                for(int j=0;j<listNum2.size();j++){
                    Map map2=(Map) listNum2.get(j);
                    mapGroupTwo.putAll(map2);
                }
                mapGroupTwo.remove("day");
                list2.add(mapGroupTwo);
                hashMap.put("tableData",list2);
            }
            long f=System.currentTimeMillis();
            System.out.println("查询其他==========="+(f-e)/1000+"秒");
        }catch ( Exception e){
            e.printStackTrace();
        }
//        System.out.println(list);
        return hashMap;
    }
}